package com.elai.web.controller.baseconfig;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.elai.common.annotation.Log;
import com.elai.common.core.controller.BaseController;
import com.elai.common.core.domain.AjaxResult;
import com.elai.common.enums.BusinessType;
import com.elai.baseconfig.domain.EventMethodGlobal;
import com.elai.baseconfig.service.IEventMethodGlobalService;
import com.elai.common.utils.poi.ExcelUtil;
import com.elai.common.core.page.TableDataInfo;

/**
 * 全局事件函数Controller
 *
 * @author elai
 * @date 2022-05-05
 */
@RestController
@RequestMapping("/baseconfig/global")
public class EventMethodGlobalController extends BaseController
{
    @Autowired
    private IEventMethodGlobalService eventMethodGlobalService;

    /**
     * 查询全局事件函数列表
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:global:list')")
    @GetMapping("/list")
    public TableDataInfo list(EventMethodGlobal eventMethodGlobal)
    {
        startPage();
        List<EventMethodGlobal> list = eventMethodGlobalService.selectEventMethodGlobalList(eventMethodGlobal);
        return getDataTable(list);
    }

    /**
     * 导出全局事件函数列表
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:global:export')")
    @Log(title = "全局事件函数", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(EventMethodGlobal eventMethodGlobal)
    {
        List<EventMethodGlobal> list = eventMethodGlobalService.selectEventMethodGlobalList(eventMethodGlobal);
        ExcelUtil<EventMethodGlobal> util = new ExcelUtil<EventMethodGlobal>(EventMethodGlobal.class);
        return util.exportExcel(list, "全局事件函数数据");
    }

    /**
     * 获取全局事件函数详细信息
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:global:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(eventMethodGlobalService.selectEventMethodGlobalById(id));
    }

    /**
     * 新增全局事件函数
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:global:add')")
    @Log(title = "全局事件函数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EventMethodGlobal eventMethodGlobal)
    {
        return toAjax(eventMethodGlobalService.insertEventMethodGlobal(eventMethodGlobal));
    }

    /**
     * 修改全局事件函数
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:global:edit')")
    @Log(title = "全局事件函数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EventMethodGlobal eventMethodGlobal)
    {
        return toAjax(eventMethodGlobalService.updateEventMethodGlobal(eventMethodGlobal));
    }

    /**
     * 删除全局事件函数
     */
    @PreAuthorize("@ss.hasPermi('baseconfig:global:remove')")
    @Log(title = "全局事件函数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(eventMethodGlobalService.deleteEventMethodGlobalByIds(ids));
    }
}
